//
//  AppDelegate.swift
//  fho
//
//  Created by 郭颢源 on 2021/3/19.
//

import UIKit
import Reachability

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        
        
        // Override point for customization after application launch.
        let reachability = try! Reachability()
        
        // 检测网络连接状态
        if reachability.connection == .unavailable {
            print("网络连接：不可用")
        } else {
            print("网络连接：可用")
        }
        
        // 检测网络类型
        if reachability.connection == .wifi {
            print("网络类型：Wifi")
        } else if reachability.connection == .cellular {
            print("网络类型：移动网络")
        } else {
            print("网络类型：无网络连接")
        }
        // 网络可用或切换网络类型时执行
        
        reachability.whenReachable = { reachability in
            print("判断网络状态及类型")
            // 判断网络状态及类型
        }
        
        // 网络不可用时执行
        reachability.whenUnreachable = { reachability in
            print("网络不可用时执行")
            // 判断网络状态及类型
        }
        
        do {
            // 开始监听
            try reachability.startNotifier()
        } catch {
            print("Unable to start notifier")
        }
        setupIQKeyboardManager()
        
        return true
    }
    
    // MARK: UISceneSession Lifecycle
    
    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }
    
    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
    
    
}

